//
//  CheckMoneyViewController.m
//  Item
//
//  Created by 刘炳举 on 12/19/15.
//  Copyright © 2015 Kelly. All rights reserved.
//

#import "CheckMoneyViewController.h"
#import "CheckTableViewCell.h"

@interface CheckMoneyViewController (){
    NGRightTableViewViewController*rttv;
    BOOL isSelect;
    NSMutableArray *mArray;
    UIImageView* image;
    UIButton* changeBtn;
}
@property (nonatomic, strong) NSArray *checkData;
@end

@implementation CheckMoneyViewController
@synthesize rtvv;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.topItem.title =@"资金查询";
    _checkData = [NSArray arrayWithObjects:@"可用金额",@"寸头金额",@"动态权益",@"冻结资金",@"浮动盈亏", nil];
    
    mArray = [[NSMutableArray alloc] initWithObjects:@"s:99102-075",@"222",@"333",@"444",@"555", nil];
    
    UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    
    changeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 88, 30)];
    [changeBtn setTitle:@"s:99102-075" forState:UIControlStateNormal];
    changeBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
    [rightButtonView addSubview:changeBtn];
    
    [changeBtn addTarget:self action:@selector(rightBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    image = [[UIImageView alloc] initWithFrame:CGRectMake(88,8,12,15)];
    [image setImage:[UIImage imageNamed:@"down_dark.png"]];
    [image setContentMode:UIViewContentModeScaleToFill];
    
    [rightButtonView addSubview:image];
    //把右侧的两个按钮添加到rightBarButtonItem
    UIBarButtonItem *rightCunstomButtonView = [[UIBarButtonItem alloc] initWithCustomView:rightButtonView];
    self.navigationItem.rightBarButtonItem = rightCunstomButtonView;
    
    if (!rtvv) {
        rtvv = [[NGRightTableViewViewController alloc]init];
    }
    rtvv.tableViewArray = mArray;
    rtvv.view.frame = CGRectMake(self.view.frame.size.width-120,43,100,120);
    [self addChildViewController:rtvv];
    [self.view addSubview:rtvv.view];
    rtvv.pulldelegate = self;
    [rtvv.view setHidden:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [_checkData count];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    static NSString *cellIdentifier =@"checkCell";
    
 
       UINib* nib = [UINib nibWithNibName:@"CheckTableViewCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
        tableView.separatorStyle =  UITableViewCellSelectionStyleGray;
        tableView.scrollEnabled =NO;    
    CheckTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[[CheckTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autorelease];
    }
    NSUInteger row = [indexPath row];
        cell.cName = [self.checkData objectAtIndex:row];
        cell.cNum  = @"0.00";
    return cell;

}

-(void)rightBarBtnClicked{
    if (!isSelect) {
        [rtvv.view setHidden:NO];
        isSelect=YES;
        image.transform=CGAffineTransformMakeRotation(M_PI);
    }else{
        [rtvv.view setHidden:YES];
        isSelect=NO;
        image.transform=CGAffineTransformMakeRotation(0);
    }
    
}
#pragma mark - pulldelegate
-(void)menuItemSelected:(NSIndexPath *)indexPath{
    NSLog(@"selectAcc:%@",[mArray objectAtIndex:indexPath.item]);
    [rtvv.view setHidden:YES];
    isSelect=NO;
    image.transform=CGAffineTransformMakeRotation(0);
    changeBtn.titleLabel.text = [mArray objectAtIndex:indexPath.item];
    
}

@end
